package zengjin.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zengjin.common.PageResponse;
import zengjin.common.R;
import zengjin.model.dto.bulletin.AddBulletinRequest;
import zengjin.model.dto.verification.AddVerificationRequest;
import zengjin.model.dto.verification.PageVerificationRequest;
import zengjin.model.dto.verification.UpdateVerificationRequest;
import zengjin.model.vo.verification.PageVerificationVO;
import zengjin.service.VerificationService;

/**
 * @author 19324
 */
@Tag(name = "认证相关接口")
@RestController
@RequestMapping("/verification")
@Slf4j
public class VerificationController {


    @Resource
    private VerificationService verificationService;


    //1.添加认证
    @Operation(summary = "添加认证")
    @PostMapping("/addVerification")
    public R<Boolean> addVerification(@RequestBody AddVerificationRequest addVerificationRequest) {
        //1.参数校验
        if (addVerificationRequest == null) {
            throw new RuntimeException("参数为空");
        }
        //2.调用service
        Boolean result = verificationService.addVerification(addVerificationRequest);
        //3.返回结果
        if (!result) {
            return R.error(false, "添加失败");
        }
        return R.success(true, "添加成功");
    }

    //2.分页获取认证信息
    @Operation(summary = "分页获取认证信息")
    @PostMapping("/getVerificationPage")
    public R<PageResponse<PageVerificationVO>> getVerificationPage(@RequestBody PageVerificationRequest pageVerificationRequest) {
        //1.参数校验
        if (pageVerificationRequest == null) {
            throw new RuntimeException("参数为空");
        }
        //2.调用service
        PageResponse<PageVerificationVO> pageVerification = verificationService.getVerificationPage(pageVerificationRequest);
        //3.返回结果
        return R.success(pageVerification, "查询成功");
    }

    //3.获取认证详情
    @Operation(summary = "获取认证详情")
    @PostMapping("/getVerificationDetail")
    public R<Object> getVerificationDetail(Long verificationId) {
        //1.参数校验
        if (verificationId == null) {
            throw new RuntimeException("参数为空");
        }
        //2.调用service
        Object object = verificationService.getVerificationDetail(verificationId);
        //3.返回结果
        if (object == null) {
            return R.error(null, "查询失败");
        }
        return R.success(object, "查询成功");
    }

    //4.更新认证
    @Operation(summary = "更新认证")
    @PostMapping("/updateVerification")
    public R<Boolean> updateVerification(@RequestBody UpdateVerificationRequest updateVerificationRequest) {
        //1.参数校验
        if (updateVerificationRequest == null) {
            throw new RuntimeException("参数为空");
        }
        //2.调用service
        Boolean result = verificationService.updateVerification(updateVerificationRequest);
        //3.返回结果
        if (!result) {
            return R.error(false, "更新失败");
        }
        return R.success(true, "更新成功");
    }

}
